package com.mysen.sso.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.mysen.model.Response;
import com.mysen.sso.dao.PermissionDao;
import com.mysen.sso.model.Permission;
import com.mysen.sso.service.PermissionService;

@Service
public class PermissionServiceImpl implements PermissionService {
	
	@Autowired
	private PermissionDao dao;
	
	@Override
	public Response<?> selectByPage(Permission record) {
		Response<?> resp = new Response<>();
		resp.setDatas(dao.selectByPage(record));
		resp.setTotal(dao.selectByPaeCount(record));
		resp.setSuccess(true);
		return resp;
	}
	
	@Override
	public Permission save(Permission record) {
		dao.insert(record);
		return record;
	}

	@Override
	public boolean updateById(Permission record) {
		return dao.updateById(record) == 1;
	}

	@Override
	public boolean deleteById(String id) {
		return dao.deleteById(id) == 1;
	}

	@Override
	public Permission selectById(String id) {
		return dao.selectById(id);
	}

	@Override
	public List<Permission> selectTree(String pid, boolean isAll) {
		if(isAll) {
			return dao.selectTree(pid);
		}else {
			Permission param = new Permission();
			param.setPermissionPid(pid);
			return dao.selectByPage(param);
		}
	}

}
